package com.gxa.modules.sys.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.sys.entity.Area;
import com.gxa.modules.sys.entity.Picture;
import com.gxa.modules.sys.service.PictureService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public
class PictureController {


    @Autowired
    private
    PictureService pictureService;

    @ApiOperation(value = "查询图片")
    @PutMapping("/Picture/queryAll")
    public
    Result queryAll() {


//        this.codeService.addCode(cdkeyDto,cdkeyList);

        try{

            List<Picture> pictures = pictureService.queryAll();
            return new Result().ok(pictures);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("查询数据失败");



        }

    }

    @ApiOperation(value = "改图片")
    @PutMapping("/Picture/update")
    public
    Result update(@RequestBody Picture picture) {


//        this.codeService.addCode(cdkeyDto,cdkeyList);

        try{

             pictureService.updatePicture(picture);
            return new Result().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error();



        }

    }


    @ApiOperation(value = "删图片")
    @DeleteMapping("/Picture/delete")
    public
    Result delete(Integer id) {


//        this.codeService.addCode(cdkeyDto,cdkeyList);

        try{

            pictureService.deletePicture(id);
            return new Result().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("查询数据失败");



        }

    }

    @ApiOperation(value = "加图片")
    @PostMapping("/Picture/insert")
    public
    Result insert(@RequestBody Picture picture) {


//        this.codeService.addCode(cdkeyDto,cdkeyList);

        try{

            pictureService.insertPicture(picture);
            return new Result().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error();



        }

    }



}
